public class Test2 {
//    public static final double C = 12.01;
//    public static final double H = 1.008;
//    public static final double O = 16.00;
//    public static final double N = 14.01;
    public static void main(String[] args) {
        System.out.println(Molar("C6H5OH"));
    }
    public static double Molar(String str){
        int num = 0,k=0,light=0;
        double sum=0;
        for (int i = str.length()-1; i >=0; i--) {
            char c = str.charAt(i);
            if (c >= 'A' && c <= 'Z') {
                if (k == 0) k = 1;
                switch (c) {
                    case 'C':
                        sum += k * 12.01;break;
                    case 'H':
                        sum += k * 1.008;break;
                    case 'O':
                        sum += k * 16.00;break;
                    case 'N':
                        sum += k * 14.01;break;
                }
                k = 0;
                light = 0;
            } else {
                k += (int)(c-48) * (int)Math.pow(10, light++);
            }
        }
        return sum;
    }
}
